<?php 
include("conexao.php");

$id = $_GET["id"];

$consulta = "select * from vendas where id_plano='$id'";
$result   = mysql_query($consulta, $conexao);

$linha  = mysql_fetch_object($result);


if($linha == null){

	
	$query = "delete from plano where id_plano=".$id;
	$res   = mysql_query($query, $conexao);
	
	if($res){
		echo "
		<META HTTP-EQUIV=REFRESH CONTENT='0; URL=cad_plano.php'>
		<script type=\"text/javascript\">
		alert(\"Plano deletado com sucesso.\");
		</script>
		";
	}
	
	else{
		echo "
		<META HTTP-EQUIV=REFRESH CONTENT='0; URL=cad_plano.php'>
		<script type=\"text/javascript\">
		alert(\"Erro ao deletar Plano.\");
		</script>
		";
	}
	
	}else{
	
		echo "
		<META HTTP-EQUIV=REFRESH CONTENT='0; URL=cad_plano.php'>
		<script type=\"text/javascript\">
		alert(\"Existe vendas com esse Plano.\");
		</script>
		";
	
	
	}







?>